package cn.team11.smarteye.impl;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;

import org.apache.commons.lang3.StringUtils;

import cn.team11.smarteye.contract.DeviceBindingContract;
import cn.team11.smarteye.service.CatEyeService;
import cn.team11.smarteye.utils.ToastUtil;
import cn.team11.smarteye.utils.WifiUtils;

/**
 * Created by Yang on 2017/11/1.
 */

public class DeviceBindingPresenterImpl implements DeviceBindingContract.Presenter {


    private DeviceBindingContract.View mView;

    public DeviceBindingPresenterImpl(DeviceBindingContract.View mView) {
        this.mView = mView;
        mView.setPresenter(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void ackAddDeviceResponse(String reqid, int allow) {
        if (CatEyeService.icvss != null){
            CatEyeService.icvss.equesAckAddResponse(reqid, allow);
        }
    }

    @Override
    public Bitmap createQrCodeImage(String ssid, String pwd, String keyid, String username) {
        if (CatEyeService.icvss != null){
            return CatEyeService.icvss.equesCreateQrcode(ssid, pwd, keyid, username, 2, 100);
        }
        return null;
    }

    @Override
    public String getNetworkName() {
          try {
            Context ctx = mView.getContext();
            if (ctx instanceof Activity){
                ctx = ctx.getApplicationContext();
            }
            String ssid = WifiUtils.getSSID(ctx);
            if (StringUtils.isEmpty(ssid)){
                mView.showToast(ToastUtil.NEGATIVE_TOAST,"请打开WIFI网络!");
                return "";
            } else {
                return ssid;
            }
        } catch (Exception e){
            e.printStackTrace();
              return "";
        }
    }
}
